package com.jsnu.xiaochi.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jsnu.xiaochi.dao.BannerMapper;
import com.jsnu.xiaochi.dao.FoodMapper;
import com.jsnu.xiaochi.pojo.Banner;
import com.jsnu.xiaochi.pojo.BannerExample;
import com.jsnu.xiaochi.pojo.Food;
import com.jsnu.xiaochi.pojo.FoodExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {

    @Resource
    BannerMapper bannerMapper;
    @Resource
    FoodMapper foodMapper;
    @Override
    public List<Banner> getBanner() {
        BannerExample bannerExample = new BannerExample();
        List<Banner> banners = bannerMapper.selectByExample(bannerExample);
        return banners;
    }

    @Override
    public PageInfo<Food> findDelicious() {
        FoodExample foodExample=new FoodExample();
        foodExample.setOrderByClause("create_time desc");
        foodExample.createCriteria().andStatusEqualTo("1");
        PageHelper.startPage(1,10);
        List<Food> foods=foodMapper.selectByExample(foodExample);
        PageInfo<Food> pageInfo = new PageInfo<Food>(foods);
        return pageInfo;
    }

    @Override
    public PageInfo<Food> findRecommend() {
        FoodExample foodExample=new FoodExample();
        foodExample.setOrderByClause("score desc");
        foodExample.createCriteria().andStatusEqualTo("1");
        PageHelper.startPage(1,10);
        List<Food> foods=foodMapper.selectByExample(foodExample);
        PageInfo<Food> pageInfo = new PageInfo<Food>(foods);
        return pageInfo;
    }

    @Override
    public List<Food> getAllFood() {
        FoodExample foodExample= new FoodExample();
        foodExample.createCriteria().andStatusEqualTo("1");
        return foodMapper.selectByExample(foodExample);
    }
}
